
#pragma once

#include <stdio.h>
#include <math.h>

//Contains portion of file data.
template <class T>
class Buffer
{
	private:
		size_t max_size;
		size_t size;
		size_t offset;
		T *data;
	public:
		//Creates empty buffer with given size.
		Buffer(size_t max_size)
		{
			this->max_size = max_size;
			this->size = 0;
			this->offset = 0;
			this->data = new T[max_size];
		}
		//Returns current size of buffer.
		inline size_t getSize()
		{ return size; }
		//Sets new size for buffer (which should be lesser then max_size).
		inline void setSize(size_t size)
		{ this->size = min(size, max_size); }
		//Returns max available size of buffer.
		inline size_t getMaxSize()
		{ return max_size; }
		//Returns offset of stored data.
		inline size_t getOffset()
		{ return offset; }
		//Sets offset.
		inline void setOffset(size_t offset)
		{ this->offset = offset; }
		//Returns n-th element of the buffer.
		inline T &operator [](const size_t n)
		{ return data[n]; }
		//Returns reference to the first element.
		inline operator T *()
		{ return data; }
		~Buffer()
		{ delete[] data; }
};
